package com.imddysc.springbootbatch001.utils;

import java.io.Serializable;

public class ResultUtils implements Serializable {

	private static final long serialVersionUID = 1;
		
	public ResultUtils() {
	}
	
	/** 成功，生成返回成功的结果 */
	public static Result success() {
		Result result = new Result();
		result.setResultCode(ResultCode.SUCCESS);
		return result;
	}
	
	/** 成功，加上data 生成返回成功的结果 */
	public static Result success(Object data) {
		Result result = new Result();
		result.setResultCode(ResultCode.SUCCESS);
		result.setData(data);
		return result;
	}
	
	/** 失败， 生成返回失败的结果 */
	public static Result failure() {
		Result result = new Result();
		result.setResultCode(ResultCode.FAILURE);
		return result;
	}
	
	/** 失败，加上data 生成返回失败的结果 */
	public static Result failure(Object data) {
		Result result = new Result();
		result.setResultCode(ResultCode.FAILURE);
		result.setData(data);
		return result;
	}
	
	/** 根据code,message(2要素)生成返回结果 */
	public static Result codeMessage(Integer code, String message) {
		Result result = new Result();
		result.setCode(code);
		result.setMessage(message);
		return result;
	}
	
	/** 根据code,message,data(3要素)生成返回结果 */
	public static Result codeMessageData(Integer code, String message, Object data) {
		Result result = new Result();
		result.setCode(code);
		result.setMessage(message);
		result.setData(data);
		return result;
	}
	
	/** 根据ResultCode 生成返回结果 */
	public static Result resultCodeMessage(ResultCode resultCode) {
		Result result = new Result();
		result.setResultCode(resultCode);
		return result;
	}
	
	/** 根据ResultCode加上data 生成返回结果 */
	public static Result resultCodeMessageData(ResultCode resultCode, Object data) {
		Result result = new Result();
		result.setResultCode(resultCode);
		result.setData(data);
		return result;
	}

}
